<?php
$title_header = "User";
$form_action = "manage/user_add";
$return_url = "manage/user";
?>
<div class="container-fluid">


    <!-- Page Heading -->
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">

                <?php
                if ($id != 0) {
                    echo 'Edit ' . $title_header;
                } else {
                    echo 'Create ' . $title_header;
                }
                ?> 
            </h1>
            <ol class="breadcrumb">
                <li>
                    <i class="fa fa-venus-mars"></i>  <a class="return-breadcrumb" href="<?php echo site_url($return_url); ?>"><?php echo $title_header; ?></a>
                </li> 
                <li>
                    <i class="fa  
                    <?php
                    if ($id != 0) {
                        echo 'fa-pencil-square-o';
                    } else {
                        echo 'fa-plus-square';
                    }
                    ?> ">
                    </i>  
                    <a href="#">
<?php
if ($id != 0) {
    echo 'Edit';
} else {
    echo 'Create';
}
?>
                    </a>
                </li>
            </ol>
        </div>
    </div>
    <!-- /.row -->

    <div class="row">
        <div class="col-lg-6">
            <form enctype="multipart/form-data" class="form-horizontal" id="form-edit" name="form-edit" 
                  method="post" autocomplete="off" 
                  action="<?php echo site_url($form_action); ?>"
                  data-fv-framework="bootstrap"
                  data-fv-icon-valid="glyphicon glyphicon-ok"
                  data-fv-icon-invalid="glyphicon glyphicon-remove"
                  data-fv-icon-validating="glyphicon glyphicon-refresh">

                <input type="hidden" name="id" value="<?php echo $id ?>"/>                    
                <div class="form-group">
                    <label class="col-xs-3 control-label">First name</label>
                    <div class="col-xs-6">
                        <input type="text" class="form-control" name="first_name" placeholder="First name"
                               data-fv-row=".col-xs-6"
                               data-fv-notempty="true"
                                
                               data-fv-notempty-message="The first name is required"
                               value="<?php echo $first_name ?>"/>
                    </div>
                </div>  
                <div class="form-group">
                    <label class="col-xs-3 control-label">Last Name</label>
                    <div class="col-xs-6">
                        <input type="text" class="form-control" name="last_name" placeholder="Last name"
                               data-fv-row=".col-xs-6"
                               data-fv-notempty="true"
                               data-fv-notempty-message="The last name is required"
                               value="<?php echo $last_name ?>"/>
                    </div>
                </div>  
                <div class="form-group">
					<label class="col-xs-3 control-label">Bussiness Name</label>
					<div class="col-xs-6">
						<input type="text" class="form-control" name="business_name" placeholder="Business name"
							data-fv-row=".col-xs-6"
							data-fv-notempty="true"
							data-fv-notempty-message="The field is required"
                                                        value="<?php echo $business_name?>"/>
					</div>
				</div>  
                
                
                <div class="form-group">
					<label class="col-xs-3 control-label">User Type</label>
					<div class="col-xs-6">
                                            <select
                                                class="form-control"
                                                id="user_type_id"
                                                name="user_type_id"
                                                data-fv-row=".col-xs-6" 
                                                data-fv-notempty="true"
                                                data-fv-notempty-message="The user type is required"
                                            >
                                               <?php 
                                                $count=0;
                                                foreach($user_type_list as $row)
                                                { 
                                                  echo  '<option '.($user_type_id == $row->id ? 'selected="selected"' : '' ) .'value="'.$row->id.'"'.'>' 
                                                            .$row->name
                                                        .'</option>';
                                                 }
                                                ?>
                                            </select>
					</div>
		</div> 
                 <div class="form-group">
					<label class="col-xs-3 control-label">User Name</label>
					<div class="col-xs-6">
						<input type="text" class="form-control" name="user_name" placeholder="User name"
							data-fv-row=".col-xs-6"
							data-fv-notempty="true"
							data-fv-notempty-message="The user is required"
                                                        value="<?php echo $user_name?>"/>
					</div>
		</div> 
                
                <div class="form-group">
					<label class="col-xs-3 control-label">Password</label>
					<div class="col-xs-6">
						<input type="text" class="form-control" name="password" placeholder="Password"
							data-fv-row=".col-xs-6"
							data-fv-notempty="true"
							data-fv-notempty-message="The password is required"
                                                        value="<?php echo $password?>"/>
					</div>
		</div> 
                
                 <div class="form-group">
					<label class="col-xs-3 control-label">Email</label>
					<div class="col-xs-6">
						<input type="text" class="form-control" name="email" placeholder="Email"
							data-fv-row=".col-xs-6"
							data-fv-notempty="true"
                                                        data-fv-emailaddress="true"
							data-fv-notempty-message="The field is required"
                                                        value="<?php echo $email?>"/>
					</div>
		</div> 
                 <div class="form-group">
					<label class="col-xs-3 control-label">Telephone</label>
					<div class="col-xs-6">
						<input type="text" class="form-control" name="tel" placeholder="Telephone"
							data-fv-row=".col-xs-6"
							data-fv-notempty="true"
							data-fv-notempty-message="The field is required"
                                                        value="<?php echo $tel?>"/>
					</div>
		</div> 

              

                <div class="form-group">
                    <div class="col-xs-9 col-xs-offset-3">
                        <button type="submit" class="btn btn-primary" name="signup" value="Sign up">Submit</button>
                    </div>
                </div>
            </form>

        </div> 
    </div>

</div>
<p><tt id="results"></tt></p>
<script type="text/javascript">

    $(document).ready(function () {

        $('#form-edit').formValidation()
                .on('success.form.fv', function (e, data) {
                    e.preventDefault();
                    var $form = $(e.target);
                    app.wait();
                    $.ajax({
                        url: $form.attr('action'),
                        type: "post",
                        data: $form.serialize(),
                        success: function (data)
                        {
                            $('#page-wrapper').html(data);
                            refreshAjax();
                            app.ready();
                        }
                    });
                });


        $(".return-breadcrumb").click(function () {
            app.wait();
            $.ajax({
                url: $(this).attr('href'),
                type: "get",
                success: function (data)
                {
                    $('#page-wrapper').html(data);
                    refreshAjax();
                    app.ready();
                },
                error: function (e)
                {
                    alert(e);
                    return false;
                }
            });

            return false;
        });
    });
</script>

